import { Button, Space, Switch, Table } from 'antd';
import React, { useEffect, useState } from 'react'
import { getSchemaListApi } from '../../api/http';
import SearchForm from './components/SearchForm';

function Home() {
    const [arr, setArr] = useState([])
    const [name, setName] = useState("")
    const [job, setjob] = useState("")
    const [schema_name, setschema_name] = useState("")
    const listData = async () => {
        let res = await getSchemaListApi({ name, job, schema_name })
        console.log(res);
        const { code, list } = res.data
        if (code === 1) {
            setArr(list)
        }
    }
    useEffect(() => {
        listData()
    }, [name, job, schema_name])
    const onFinish = (value) => {
        setName(value.name)
        setjob(value.job)
        setschema_name(value.schema_name)
    }
    const cz = () => {
        setName("")
        setjob("")
        setschema_name("")
    }
    const columns = [
        {
            title: 'ID',
            dataIndex: 'id',
        },
        {
            title: '姓名',
            dataIndex: 'name',
        },
        {
            title: '公司职位',
            dataIndex: 'job',
        },
        {
            title: '公司',
            dataIndex: 'schema_name',
        },
        {
            title: '状态',
            dataIndex: 'status',
            render: (status) => (
                <Switch checked={status === 1}></Switch>
            )
        },
        {
            title: '操作',
            render: (item) => (
                <Space>
                    <Button>编辑</Button>
                    <Button>删除</Button>
                </Space>
            ),
        },
    ];
    return (

        <div>
            <SearchForm onFinish={onFinish} cz={cz} />
            <Table dataSource={arr} columns={columns}
                rowKey='id'
            />;
        </div>
    )
}

export default Home
